﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Bingosoft.Common.Logging;
using HHMMS.Core.Common;
using System.Web.UI;

namespace HHMMS.UI.Common
{
    public class ResourceHandler : IHttpHandler
    {
        // Fields
        private static readonly ILog log = LogManager.GetCurrentClassLogger();

        // Methods
        public void ProcessRequest(HttpContext context)
        {
            var controlName = context.Request["name"];
            if (string.IsNullOrEmpty(controlName))
            {
                context.Response.Write("必须指定参数：name");
                context.Response.End();
            }

            var controlPath = string.Format("~/Modules/FileTemplate/{0}.ascx", controlName);
            var viewManager = new ViewManager<UserControl>();
            var control = viewManager.LoadViewControl(controlPath);

            context.Response.ContentType = "text/html";
            string str = viewManager.RenderView(control);
            context.Response.Write(str);
            context.Response.End();
        }

        // Properties
        public bool IsReusable
        {
            get
            {
                return true;
            }
        }
    }
}
